package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 统计周期枚举
 *
 * 管理成绩统计的时间周期，包括每日、每周、每月、每季度、每年等周期
 *
 * @author System
 * @version 1.0.0
 */
public enum StatisticsPeriod implements BaseEnum {

    /**
     * 每日
     */
    DAILY("DAILY", "每日"),

    /**
     * 每周
     */
    WEEKLY("WEEKLY", "每周"),

    /**
     * 每月
     */
    MONTHLY("MONTHLY", "每月"),

    /**
     * 每季度
     */
    QUARTERLY("QUARTERLY", "每季度"),

    /**
     * 学期
     */
    SEMESTER("SEMESTER", "学期"),

    /**
     * 每年
     */
    YEARLY("YEARLY", "每年"),

    /**
     * 自定义
     */
    CUSTOM("CUSTOM", "自定义");

    private final String code;
    private final String description;

    StatisticsPeriod(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     */
    public static StatisticsPeriod fromCode(String code) {
        for (StatisticsPeriod period : values()) {
            if (period.getCode().equals(code)) {
                return period;
            }
        }
        throw new IllegalArgumentException("Unknown statistics period code: " + code);
    }

    /**
     * 从描述创建枚举实例
     *
     * @param description 枚举描述
     * @return 对应的枚举实例
     */
    public static StatisticsPeriod fromDescription(String description) {
        for (StatisticsPeriod period : values()) {
            if (period.getDescription().equals(description)) {
                return period;
            }
        }
        throw new IllegalArgumentException("Unknown statistics period description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}